package main

import (
	"fmt"
	"sync"
	"time"
)

var wg sync.WaitGroup

func func1() {
	for i := 0; i < 10; i++ {
		time.Sleep(time.Duration(5) * time.Millisecond)
		fmt.Println("aaaaaaaaaa")
	}
}

func func2() {
	wg.Add(10)
	for i := 0; i < 10; i++ {
		time.Sleep(time.Duration(5) * time.Millisecond)
		go put()
	}
	wg.Wait()
}

func put() {
	defer wg.Done()
	fmt.Println("bbbbbbbbbb")
}

func main1() {

	t0 := time.Now()
	func1()
	t1 := time.Now()
	fmt.Println("func1", t1.Sub(t0))

	t0 = time.Now()
	func2()
	t1 = time.Now()
	fmt.Println("func2", t1.Sub(t0))

}

func main() {
	fmt.Println("并发")

	go f1()
	time.Sleep(1 * time.Second)
	go f2()
	time.Sleep(1 * time.Second)
	go f3()
	time.Sleep(1 * time.Second)
	return
	select {}
}

func f1() {
	for {
		time.Sleep(1 * time.Second)
		fmt.Println("f1")
	}
}
func f2() {
	for {
		time.Sleep(1 * time.Second)
		fmt.Println("f2")
	}
}
func f3() {
	for {
		time.Sleep(1 * time.Second)
		fmt.Println("f3")
	}
}
